package org.scboy.common.dynamic.node.entityNode;

import java.util.List;

import org.scboy.common.annotation.ScriptNode;
import org.scboy.common.dynamic.node.BaseNode;
import org.scboy.utils.entitys.coobi.Model;

import cn.hutool.json.JSONObject;

@ScriptNode("ENTITY_CREATE")
public class EntityNode extends BaseNode{

	@Override
	public void create(JSONObject object) {
		
	}

	@Override
	public Object run() {
		
		/**
		 * 测试日志
		 */
		if(this.script.isTest()) {
			this.script.appendMsg("----->开始执行："+getNodeName()+" 节点ID："+this.getId());
		}
		
		/**
		 * 流出节点
		 */
		BaseNode runTo = getRunTo("to");
		
		Model data=Model.create();
		
		Model _data=getSourceData("entity", false, Model.class);
		if(_data!=null) {
			data=_data;
		}
		
		//合并追加
		List<Model> mergeList=getSourceDatas("params", false, Model.class);
		for (Model mergeData : mergeList) {
			
			for (String key : mergeData.keySet()) {
				data.put(key, mergeData.get(key));
			}
			
			for (String columnName : mergeData.rcColumns()) {
				data.addRc(columnName);
			}
			
			for (String columnName : mergeData.nrcColumns()) {
				data.addNrc(columnName);
			}
		}
		
		this.setData("data", data);
		
		/**
		 * 测试日志
		 */
		if(this.script.isTest()) {
			this.script.appendMsg("缓存数据：\r\n"+entityToString(this.getDataAll()));
			this.script.appendMsg("执行下个节点："+runTo.getNodeName()+" 节点ID："+runTo.getId());
		}
		return runTo.run();
	}

}
